home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6844 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  60 lines

  1. Path: sun001.spd.dsccc.com!spd!jmccarty
  2. From: jmccarty@spd.dsccc.com (Mike McCarty)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Tradition or what?
  5. Date: 15 Feb 1996 18:53:20 GMT
  6. Organization: DSC Communications Corporation, Plano, Texas USA
  7. Message-ID: <4fvvf0$f9c@sun001.spd.dsccc.com>
  8. References: <1996Feb13.115611.73989@cc.usu.edu>
  9. NNTP-Posting-Host: aplo139.spd.dsccc.com
  10.  
  11. In article <1996Feb13.115611.73989@cc.usu.edu>,
  12. Erik van Renselaar <erik@cc.usu.edu> wrote:
  13. )Hi all,
  14. )
  15. )Can anyone tell me what the use is of returning
  16. )the same value for the function and one of the
  17. )output parameters, like it is done in strcpy?
  18. )Why return a string for the function if the 
  19. )result is in its first parameter as well?
  20. )
  21. )Is this just tradition or is it actually useful
  22. )for anything?
  23. )
  24. )Erik
  25.  
  26.  
  27. It would have been much better had such tools returned the END ADDRESS
  28. rather than the beginning. Someone thought it might be nice to do things
  29. like 
  30.     puts(srtcat(strcpy(buffer,"The string is: "),string));
  31.  
  32. Which I consider to be ugly. 
  33.  
  34. Had the routines returned the end address (i.e. of the terminating nul)
  35. one could have done this:
  36.  
  37.     char    *location;
  38.  
  39.     location = buffer;
  40.  
  41.     location = strcpy(location,"The string is: ");
  42.     location = strcat(location,string);
  43.     location = strcat(location," ");
  44.     ...
  45.     puts(buffer);
  46.  
  47. Which I consider to be elegant.
  48.  
  49. And not paid the overhead of reprocessing the strings to get to the end
  50. over and over.
  51.  
  52. So IMHO, there is no particular use for those return addresses. They are
  53. pretty much useless.
  54.  
  55. Mike
  56. ----
  57. char *p="char *p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
  58.  
  59. I don't speak for DSC.         <- They make me say that.
  60.